import Vue from 'vue';

import CustomModal from './custom-modal.vue';
import TiaoyaModal from './tiaoya-modal.vue';
export default {
  appendNode: document.body,
  customVNode: null,
  customVModal: null,
  tiaoyaVNode: null,
  tiaoyaVModal: null,
  initCustomModal () {
    this.customVNode = new Vue({
      render: h => h(CustomModal, {
        ref: 'modal',
        class: 'mapmodal'
      })
    }).$mount();
    this.customVModal = this.customVNode.$refs.modal;
    this.appendNode.appendChild(this.customVNode.$el);
  },
  openCustomModal (oid) {
    if (!this.customVModal) {
      this.initCustomModal();
    }
    this.customVModal.setOid(oid);
  },
  initTiaoyaModal () {
    this.tiaoyaVNode = new Vue({
      render: h => h(TiaoyaModal, {
        ref: 'modal',
        class: 'mapmodal'
      })
    }).$mount();
    this.tiaoyaVModal = this.tiaoyaVNode.$refs.modal;
    this.appendNode.appendChild(this.tiaoyaVNode.$el);
  },
  openTiaoyaModal (devId) {
    if (!this.tiaoyaVModal) {
      this.initTiaoyaModal();
    }
    this.tiaoyaVModal.setDevId(devId);
  },
  destoryModal () {
    if (this.customVNode) {
      this.customVNode.$destroy();
      this.appendNode.removeChild(this.customVNode.$el);
      this.customVNode = null;
      this.customVModal = null;
    }
    if (this.tiaoyaVNode) {
      this.tiaoyaVNode.$destroy();
      this.appendNode.removeChild(this.tiaoyaVNode.$el);
      this.tiaoyaVNode = null;
      this.tiaoyaVModal = null;
    }
  }
};
